package com.wwj.controller.user;


import com.wwj.common.result.PageResult;
import com.wwj.common.result.Result;
import com.wwj.pojo.dto.OrderDTO;
import com.wwj.pojo.dto.OrderPageQueryDTO;
import com.wwj.pojo.dto.SetmealPageQueryDTO;
import com.wwj.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController("userOrderController")
@RequestMapping("/user/order")
@Slf4j
@Api(tags="体检预约相关接口")
public class OrderController {

    @Resource
    private OrderService orderService;

    @PostMapping
    @ApiOperation(value = "新增预约单")
    @CacheEvict(cacheNames = "OrderCache",allEntries = true)
    public Result save(@RequestBody OrderDTO orderDTO){
        orderService.save(orderDTO);
        return Result.success();
    }

    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    @Cacheable(cacheNames = "OrderCache",key = "#orderPageQueryDTO.userId")
    public Result<PageResult> pageQuery(OrderPageQueryDTO orderPageQueryDTO){
        PageResult pageResult=orderService.pageQueryUser(orderPageQueryDTO);
        return Result.success(pageResult);
    }
}
